package com.haotunet.app.goldtreasure.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.haotunet.app.goldtreasure.R;
import com.haotunet.app.goldtreasure.model.WalletDetailInfo;

import java.util.List;

public class FinancialDetailAdapter extends HolderAdapter<WalletDetailInfo, FinancialDetailAdapter.ViewHolder> {

    public FinancialDetailAdapter(Context context, List<WalletDetailInfo> mlist) {
        super(context, mlist);
    }

    public static class ViewHolder {
        TextView tvSource;
        TextView tvDate;
        TextView tvAmount;
    }

    @Override
    public View buildConvertView(LayoutInflater layoutInflater, WalletDetailInfo t, int position) {
        return inflate(R.layout.item_financial_detail);
    }

    @Override
    public ViewHolder buildHolder(View convertView, WalletDetailInfo t, int position) {
        ViewHolder holder = new ViewHolder();
        holder.tvAmount = (TextView) convertView.findViewById(R.id.txt_amount);
        holder.tvDate = (TextView) convertView.findViewById(R.id.txt_date);
        holder.tvSource = (TextView) convertView.findViewById(R.id.txt_financial_source);
        return holder;
    }

    @Override
    public void bindViewDatas(View convertView, ViewHolder holder, WalletDetailInfo walletDetailInfo, int position) {
        if ("+".equals(walletDetailInfo.getAmount().trim().substring(0, 1))) {
            holder.tvAmount.setTextColor(context.getResources().getColor(R.color.color_red));
        } else if ("-".equals(walletDetailInfo.getAmount().trim().substring(0, 1))) {
            holder.tvAmount.setTextColor(context.getResources().getColor(R.color.color_green));
        } else {
            holder.tvAmount.setTextColor(context.getResources().getColor(R.color.color_black));
        }
        holder.tvAmount.setText(walletDetailInfo.getAmount());
        holder.tvDate.setText(walletDetailInfo.getTransactionTime());
        holder.tvSource.setText(walletDetailInfo.getOperation());
    }
}
